home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / ActiveX Mac SDK / ActiveX SDK / Sample Controls / Menus / CPopupMenuTracker.cp < prev    next >
Encoding:
Text File  |  1996-12-20  |  4.2 KB  |  167 lines  |  [TEXT/CWIE]

  1.  
  2. ///////////////////////////////////////////////////////////////////////////////
  3. //
  4. // CPopupMenuTracker.cp
  5. //
  6.  
  7. #include "ocheaders.h"
  8. #include "FnAssert.h"
  9. #include "CPopupMenuTracker.h"
  10.  
  11.  
  12. ///////////////////////////////////////////////////////////////////////////////
  13. //
  14. // Private Data Structures & constants
  15. //
  16.  
  17. union Converter
  18. {
  19.     struct
  20.     {
  21.         short hiWd, loWd;
  22.     } shortVal;
  23.     long message;
  24. };
  25.  
  26. const short bulletMark = 165; // char code 165 = bullet mark in most fonts
  27.  
  28. ///////////////////////////////////////////////////////////////////////////////
  29. //
  30. // CPopupMenuTracker::CPopupMenuTracker
  31. //
  32.  
  33. CPopupMenuTracker::CPopupMenuTracker(    CPopupMenuControl *    control,
  34.                         MenuHandle            itsMenu,
  35.                         short                currentItemNumber,
  36.                         short                fontID,
  37.                         short                fontSize)
  38. {
  39.     ASSERT((control!= NULL), "NULL control in temporary popup!");
  40.     
  41.     mControl                = control;
  42.     mMenu                     = itsMenu;
  43.     mCurrentItem.itemNumber    = currentItemNumber;
  44.     mFontID                    = fontID;
  45.     mFontSize                = fontSize;
  46.  
  47. //    AcquirePort();
  48.         
  49.     if (::CountMItems(itsMenu) > 0)
  50.         ::CalcMenuSize(itsMenu);
  51.     
  52.     if (mMenu)
  53.         ::InsertMenu(mMenu, hierMenu);
  54.  
  55. ///////////////////////////////////////////////////////////////////////////////
  56. //
  57. // CPopupMenuTracker::CPopupMenuTracker
  58. //
  59.  
  60. CPopupMenuTracker::CPopupMenuTracker(    CPopupMenuControl *    control,
  61.                         MenuHandle            itsMenu,
  62.                         short                currentItemNumber)
  63. {
  64.     mControl                = control;
  65.     mMenu                     = itsMenu;
  66.     mCurrentItem.itemNumber    = currentItemNumber;
  67.     mFontID                    = geneva;
  68.     mFontSize                = 9;
  69.     
  70.     if (::CountMItems(itsMenu) > 0)
  71.         ::CalcMenuSize(itsMenu);
  72.     
  73.     if (mMenu)
  74.         ::InsertMenu(mMenu, hierMenu);
  75.         
  76.  
  77. ///////////////////////////////////////////////////////////////////////////////
  78. //
  79. // CPopupMenuTracker::~CPopupMenuTracker
  80. //
  81.  
  82. CPopupMenuTracker::~CPopupMenuTracker()
  83. {
  84.     if (mMenu)
  85.     {
  86.         short theMenuID = (*mMenu)->menuID;
  87.         ::DeleteMenu(theMenuID);
  88.     }
  89.  
  90. ///////////////////////////////////////////////////////////////////////////////
  91. //
  92. // CPopupMenuTracker::TrackMouse
  93. //
  94.  
  95. short CPopupMenuTracker::TrackMouse(Point& theMouse)
  96. {
  97.     if (mMenu)
  98.     {
  99.         // Note: we're assuming theMouse is in global coordinates, so theres
  100.         // no need to call ::LocalToGlobal(&theMouse);
  101.  
  102.         short savedFontFamily    = LMGetSysFontFam();    //%BD jdo 28oct96    modified to live in Copland world
  103.         short savedFontSize        = LMGetSysFontSize();    //%BD jdo 28oct96    ditto
  104.         
  105.         // set up for our work:
  106.         LMSetSysFontFam(mFontID);            //%BD jdo 28oct96    set font ID - using supported API
  107.         LMSetSysFontSize(mFontSize);        //%BD jdo 28oct96    set font size - using supported API
  108.         LMSetLastSPExtra( -1);                 //%BD jdo 28oct96    forces the font manager to re-cache the sysfont & size - use supported API
  109.         
  110.         SetItemMark(mMenu, mCurrentItem.itemNumber, bulletMark); 
  111.         
  112.         Converter menuResult;
  113.         menuResult.message = PopUpMenuSelect(mMenu, theMouse.v, theMouse.h, mCurrentItem.itemNumber); 
  114.         
  115.         SetItemMark(mMenu, mCurrentItem.itemNumber, noMark);
  116.         
  117.         // put things back the way we found them:
  118.         LMSetSysFontFam(savedFontFamily);    //%BD jdo 28oct96    modified to live in Copland world
  119.         LMSetSysFontSize(savedFontSize);    //%BD jdo 28oct96    ditto
  120.         LMSetLastSPExtra( -1);                 //%BD jdo 28oct96    forces the font manager to re-cache the sysfont & size - use supported API
  121.             
  122.         if (menuResult.shortVal.loWd)
  123.             mCurrentItem.itemNumber = menuResult.shortVal.loWd;
  124.     }
  125.     
  126.     return mCurrentItem.itemNumber;
  127.  
  128. ///////////////////////////////////////////////////////////////////////////////
  129. //
  130. // CPopupMenuTracker::GetCurrentItem
  131. //
  132.  
  133. void CPopupMenuTracker::GetCurrentItem(CMenuItem * menuItem)
  134. {
  135.     ASSERT(menuItem != NULL, "Null menu item object in CPopupMenuTracker::GetCurrentItem");
  136.     
  137.     menuItem->itemNumber = GetCurrentItemNumber();
  138.     strcpy(menuItem->itemText, GetCurrentItemText());
  139.  
  140. ///////////////////////////////////////////////////////////////////////////////
  141. //
  142. // CPopupMenuTracker::GetCurrentItemNumber
  143. //
  144.  
  145. short CPopupMenuTracker::GetCurrentItemNumber(void)
  146. {
  147.     return mCurrentItem.itemNumber;    
  148.  
  149. ///////////////////////////////////////////////////////////////////////////////
  150. //
  151. // CPopupMenuTracker::GetCurrentItemText
  152. //
  153.  
  154. char * CPopupMenuTracker::GetCurrentItemText(void)
  155. {
  156.     ::GetItem(mMenu, mCurrentItem.itemNumber, ((StringPtr)mCurrentItem.itemText));
  157.     p2cstr(((StringPtr)mCurrentItem.itemText));
  158.     
  159.     return mCurrentItem.itemText;
  160.